package com.v1.video.widgets;

import com.v1.video.AppManager;
import com.v1.video.activity.MainPageNewActivity;
import com.v1.video.util.Logger;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;

public class MyDialog extends Dialog{
	private final String TAG = "MyDialog";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE |
                WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
	}

	public boolean  isToCloseApp = false;
	private Context context = null;
	public MyDialog(Context context) {
		super(context);
		this.context = context;
		// TODO Auto-generated constructor stub
	}
	
	public MyDialog(Context context,boolean isToCloseApp) {
		super(context);
		this.isToCloseApp = isToCloseApp;
		this.context = context;
		// TODO Auto-generated constructor stub
	}
	
	public MyDialog(Context context, int theme){
		super(context, theme);
		this.context = context;
	}
	
	public MyDialog(Context context, int theme,boolean isToCloseApp){
		super(context, theme);
		this.isToCloseApp = isToCloseApp;
		this.context = context;
	}
	
	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		// TODO Auto-generated method stub
		if (event.getKeyCode()==KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0){
			Logger.i(TAG, "mydialog的dispatchKeyEvent方法执行了");
		    this.dismiss();
		    if(isToCloseApp){
		    	AppManager.getAppManager().AppExit(context);
		    }
		}
		return super.dispatchKeyEvent(event);
	}
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent ev) {
		// TODO Auto-generated method stub
		switch (ev.getAction()) {
		case MotionEvent.ACTION_DOWN:
//		    this.dismiss();
			break;
		default:
			break;
		}
		return super.dispatchTouchEvent(ev);
	}

}
